package com.briup.app01.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app01.bean.Category;
import com.briup.app01.service.ICategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/category")
@RestController
@Api(description="category栏目描述")
public class CategoryController {
	@Autowired
	private ICategoryService categoryService;

//	@RequestMapping("/save")
//	public String save(Category category) {
//		categoryService.save(category);
//		return "保存成功";
//
//	}

	@ApiOperation("查询所有栏目信息")
	@GetMapping("/findAll")
	public List<Category> findAll() {
		return categoryService.findAll();
	}

	@ApiOperation("查询栏目信息通过id")
	@ApiImplicitParam(name="id",value="栏目id",required=true,dataType="Long",paramType="query")
	@GetMapping("/findAllById")
	public Category findAllById(Long id) {
		return categoryService.findById(id);
	}

	@ApiOperation("删除栏目信息通过id")
	@DeleteMapping("/deleteById")
	public String deleteById(Long id) {
		if (categoryService.delete(id)) {
			return "删除成功";
		} else {
			return "删除失败";
		}

	}

//	@ApiOperation("更新或者添加信息")
//	@GetMapping("/updateById")
//	public String updateById(Category category) {
//		if (categoryService.update(category)) {
//			return "更新成功";
//		} else {
//			return "更新失败";
//		}
//	}
	@ApiOperation(value="更新或者添加信息",notes="如果id为空为保存，否则为更新")
	@PostMapping("/saveOrUpdate")
	public String saveOrUpdate(Category category) {
		categoryService.saveOrUpdate(category);
				
		return "保存成功";}
}
